package com.moo2u2.android.oaktononthego.timesheet.dao;

import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log;

import com.moo2u2.android.oaktononthego.providers.TimesheetProvider;

public class TimesheetTable
{
    public static final String KEY_ROWID = "_id";

    public static final String KEY_ENDDATE = "enddate";

    public static final String KEY_SUBMITTED = "submitted";

    public static final String TIMESHEET_TABLE = "timesheets";
    
    /**
     * The content:// style URL for this table
     */
    public static final Uri CONTENT_URI =  Uri.parse("content://" + TimesheetProvider.AUTHORITY + "/" + TIMESHEET_TABLE);
    
    /**
     * The content URI base for a single row of data. Callers must
     * append a numeric row id to this Uri to retrieve a row
     */
    public static final Uri CONTENT_ID_URI_BASE =  Uri.parse("content://" + TimesheetProvider.AUTHORITY + "/timesheet/");
    
    private static final String TIMESHEET_CREATE = "create table " + TIMESHEET_TABLE + "(" + KEY_ROWID + " integer primary key autoincrement, "
	    + KEY_ENDDATE + " date not null, " + KEY_SUBMITTED + " boolean not null);";

    public static void onCreate(SQLiteDatabase database)
    {
	database.execSQL(TIMESHEET_CREATE);
    }

    public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion)
    {
	Log.w(TimesheetTable.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
	database.execSQL("DROP TABLE IF EXISTS " + TIMESHEET_TABLE);
	onCreate(database);
    }
}